<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/common.css" media="all">
    <link rel="stylesheet" href="../viewstyle/css/publicform.css">
    <script src="/js/layui/layui.all.js"></script>
    <script src="/admin/js/token.js"></script>
    <script src="../viewstyle/config/config2.js"></script>
</head>
<style>
    .layui-form-label {
        width: 70px;
    }

    .layui-form-item {
        text-align: left;
    }
</style>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">编号或名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="bhmc" id="bhmc" placeholder="输入站点编号或名称" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">密钥状态</label>
                    <div class="layui-input-inline">
                        <select name="role" id="zt">
                            <option value="">全部</option>
                            <option value="未使用">未使用</option>
                            <option value="使用中">使用中</option>
                            <option value="已过期">已过期</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="top: 4px">开始时间</label>
                            <div class="layui-inline">
                                <input type="text" class="layui-input kuan" id="starttime" placeholder="左下角选择时间可选择时分秒">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="top: 4px">结束时间</label>
                            <div class="layui-inline">
                                <input type="text" class="layui-input kuan" id="endtime" placeholder="左下角选择时间可选择时分秒">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-inline">
                    <button id="btnsearch" class="layui-btn layuiadmin-btn-admin" lay-submit
                            lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>搜索
                    </button>
                </div>
            </div>
        </div>


        <div class="layui-card-body">
            <table class="layui-hide" id="t" lay-filter="t"></table>
        </div>

    </div>
</div>

</body>

<script type="text/html" id="tb">
    <div class="layui-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData" onclick="getAll()">导出当前页Excel</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength" onclick="getAll()">导出所有页Excel</button>
        <a class="layui-btn layui-btn-sm" lay-href="jifei/TermainKeyZJ.html">密钥充值</a>
    </div>
</script>

<script type="text/html" id="caozuo">
    {{#if(d.terminal_key_status=='未使用'){  }}
    <a class="layui-btn layuiadmin-btn-admin layui-btn-xs" lay-event="detail">授权</a>
    {{# }else{}}
    {{# }}}
</script>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate

        //日期时间选择器
        laydate.render({
            elem: '#starttime'
            , type: 'datetime'
        })
        laydate.render({
            elem: '#endtime'
            , type: 'datetime'
        })
    })

    layui.use('table', function () {
        var $ = layui.$
        var table = layui.table
        table.render({
            elem: '#t',
            id: 'tt',
            toolbar: '#tb',
            url: 'http://localhost:8080/admin/terminal-key/selectTerminalKeys',
            cols: [
                [{
                    field: 'station_bh',
                    title: '编号',
                    width: '10%',
                    align: 'center',
                    fixed: 'left'
                },
                    {
                        field: 'station_name',
                        title: '站点名称',
                        width: '12%',
                        align: 'center'
                    },
                    {
                        field: 'terminal_mac',
                        title: 'mac地址',
                        width: '12%',
                        align: 'center'
                    },
                    {
                        field: 'terminal_room',
                        title: '房间号',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'terminal_key_value',
                        title: '密钥',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'terminal_key_status',
                        title: '状态',
                        width: '10%',
                        align: 'center'
                    },
                    {
                        field: 'terminal_key_begin_time',
                        title: '开始时间',
                        width: '15%',
                        align: 'center'
                    },
                    {
                        field: 'terminal_key_end_time',
                        title: '结束时间',
                        width: '15%',
                        align: 'center'
                    },
                    {
                        field: 'station_id',
                        title: '站点id',
                        hide: true
                    },
                    {
                        title: '操作',
                        align: 'center',
                        toolbar: '#caozuo',
                        fixed: 'right'
                    }
                ]
            ],
            page: true
        })
        //搜索的监听时间
        $('#btnsearch').click(function () {
            table.reload('tt', {
                where: {
                    station_name: $("#bhmc").val(),
                    terminal_key_status: $("#zt").val(),
                    terminal_key_begin_time: $("#starttime").val(),
                    terminal_key_end_time: $("#endtime").val()
                },
                page: {
                    curr: 1
                }
            })
        })

        $(window).keypress(function (event) {
            if (event.which === 13) {
                $('#btnsearch').click();
            }
        })
        //搜索的监听时间
        $('#butss').click(function () {
            table.reload('tt', {
                where: {
                    station_name: $("#bhmc").val(),
                    terminal_key_status: $("#zt").val(),
                    terminal_key_begin_time: $("#starttime").val(),
                    terminal_key_end_time: $("#endtime").val()
                },
                page: {
                    curr: 1
                }
            })
        })
        //监听工具条
        table.on('tool(t)', function (obj) {
            var getdata = obj.data;
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            switch (layEvent) {
                case 'detail':
                    layui.data('stationdata', {
                        key: 'getdata',
                        value: getdata
                    })
                    layer.open({
                        content: 'SelectTermain.html',
                        type: 2,
                        title: '选择终端',
                        area: ['100%', '100%']
                    });

                    break;
            }
        })
    })
    function getAll(){
        location="/admin/terminal-key/selectTerminalKeysExcel";
    }
</script>
</html>
